package kr.co.doriclassic.chapter15.menu;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JPopupMenu;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TestMain extends JFrame implements ActionListener {

	private JPanel contentPane;
	private JMenuBar menuBar;
	private JMenu menuEmp;
	private JMenu menuDep;
	private JMenuItem addItemEmp;
	private JMenuItem deleteItemEmp;
	private JMenuItem searchItemEmp;
	private JMenuItem updateItemEmp;
	private JMenuItem listItemEmp;
	private JMenuItem addItemDep;
	private JMenuItem deleteItemDep;
	private JMenuItem updateItemDep;
	private JMenuItem searchItemDep;
	private JMenuItem listItemDep;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TestMain frame = new TestMain();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TestMain() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		
		menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		
		menuEmp = new JMenu("사원정보");
		menuBar.add(menuEmp);
		
		addItemEmp = new JMenuItem("추가");
		addItemEmp.addActionListener(this);
		menuEmp.add(addItemEmp);
		
		deleteItemEmp = new JMenuItem("삭제");
		deleteItemEmp.addActionListener(this);
		menuEmp.add(deleteItemEmp);
		
		updateItemEmp = new JMenuItem("수정");
		updateItemEmp.addActionListener(this);
		menuEmp.add(updateItemEmp);
		
		searchItemEmp = new JMenuItem("검색");
		searchItemEmp.addActionListener(this);
		menuEmp.add(searchItemEmp);
		
		listItemEmp = new JMenuItem("목록");
		listItemEmp.addActionListener(this);
		menuEmp.add(listItemEmp);
		
		menuDep = new JMenu("부서정보");
		menuBar.add(menuDep);
		
		addItemDep = new JMenuItem("추가");
		menuDep.add(addItemDep);
		
		deleteItemDep = new JMenuItem("삭제");
		menuDep.add(deleteItemDep);
		
		updateItemDep = new JMenuItem("수정");
		menuDep.add(updateItemDep);
		
		searchItemDep = new JMenuItem("검색");
		menuDep.add(searchItemDep);
		
		listItemDep = new JMenuItem("목록");
		menuDep.add(listItemDep);
	
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == listItemEmp) {
			actionPerformedListItemEmp(e);
		}
		if (e.getSource() == searchItemEmp) {
			actionPerformedSearchItemEmp(e);
		}
		if (e.getSource() == updateItemEmp) {
			actionPerformedUpdateItemEmp(e);
		}
		if (e.getSource() == deleteItemEmp) {
			actionPerformedDeleteItemEmp(e);
		}
		if (e.getSource() == addItemEmp) {
			actionPerformedAddItemEmp(e);
		}
	}
	protected void actionPerformedAddItemEmp(ActionEvent e) {
		InputEmp emp = new InputEmp();
		emp.setLblNewLabel("사원정보추가");
		contentPane.removeAll();
		contentPane.add(emp);
		contentPane.revalidate();
	}
	protected void actionPerformedDeleteItemEmp(ActionEvent e) {
		InputEmp emp = new InputEmp();
		emp.setLblNewLabel("사원정보삭제");
		contentPane.removeAll();
		contentPane.add(emp);
		contentPane.revalidate();
	}
	protected void actionPerformedUpdateItemEmp(ActionEvent e) {
		InputEmp emp = new InputEmp();
		emp.setLblNewLabel("사원정보수정");
		contentPane.removeAll();
		contentPane.add(emp);
		contentPane.revalidate();
	}
	protected void actionPerformedSearchItemEmp(ActionEvent e) {
		InputEmp emp = new InputEmp();
		emp.setLblNewLabel("사원정보검색");
		contentPane.removeAll();
		contentPane.add(emp);
		contentPane.revalidate();
	}
	protected void actionPerformedListItemEmp(ActionEvent e) {
		InputEmp emp = new InputEmp();
		emp.setLblNewLabel("사원정보출력");
		contentPane.removeAll();
		contentPane.add(emp);
		contentPane.revalidate();
	}
}
